Skip to content

Conversation

@ahmad-moussawi
Copy link
Contributor

@ahmad-moussawi ahmad-moussawi commented Oct 1, 2022

This PR adds the support for the SelectAggregate method and it's siblings SelectSum, SelectMax, SelectMin, SelectAvg, SelectCount methods, this is better than using SelectRaw.

All these methods accepts an optional filter parameter to filter the aggregated column based on a specified conditions, this will translate to the Aggregation Filter clause on supported compilers like PostgreSQL, and SQLite with a fallback to CASE WHEN statement for the unsupported ones.

Related #507

@ahmad-moussawi ahmad-moussawi merged commit 31ee1e0 into master Oct 1, 2022
@ahmad-moussawi ahmad-moussawi deleted the iss-507_support_filter_clause branch October 1, 2022 06:58
@yankyhgoflow
Copy link
Contributor

👍 Thanks, this is really taking this library to the next level!

Thanks @ahmad-moussawi you rock!

@kenzouno1
Copy link

Missing alias for this feature

@ahmad-moussawi
Copy link
Contributor Author

@kenzouno1 what do you mean exactly by missing alias? is this what you are looking for?

var query = db.Query("Transaction")
                .SelectSum("Amount as Total_2020", q => q.WhereDatePart("year", "date", 2020))
                .SelectSum("Amount as Total_2021", q => q.WhereDatePart("year", "date", 2021))
                .SelectSum("Amount as Total_2022", q => q.WhereDatePart("year", "date", 2022))

check more examples here
https://github.com/sqlkata/querybuilder/blob/master/QueryBuilder.Tests/MySqlExecutionTest.cs#L237

@kenzouno1
Copy link

That's exactly what I'm looking for. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants